master @ 181 LINES
[ HISTORY ] [ UP ]
┌─ ASTRO ────────────────────────────────────────────────────────────────────┐
│ --- │
│ import PageLayout from "../../../layouts/PageLayout.astro"; │
│ import LeaderboardHeader from "../../../components/Leaderboard/LeaderboardHeader/L │
│ eaderboardHeader.astro"; │
│ import LeaderboardTable from "../../../components/Leaderboard/LeaderboardTable/Lea │
│ derboardTable.astro"; │
│ import Pagination from "../../../components/Leaderboard/Pagination/Pagination.astr │
│ o"; │
│ import DungeonFilterSelect from "../../../components/Leaderboard/DungeonFilterSele │
│ ct/DungeonFilterSelect.astro"; │
│ import LeaderboardScopeFilter from "../../../components/Leaderboard/LeaderboardSco │
│ peFilter/LeaderboardScopeFilter.astro"; │
│ import LeaderboardTypeNav from "../../../components/Leaderboard/LeaderboardTypeNav │
│ /LeaderboardTypeNav.astro"; │
│ import PlayerSearch from "../../../components/PlayerSearch/PlayerSearch.astro"; │
│ import type { LeaderboardData } from "../../../lib/types"; │
│ import { │
│ DUNGEON_MAP, │
│ dungeonNameToSlug, │
│ dungeonSlugToId, │
│ } from "../../../lib/wow-constants"; │
│ import { fetchLeaderboard } from "../../../lib/api"; │
│ │
│ export const prerender = false; │
│ │
│ // parse season from path parameter │
│ const seasonParam = Astro.params.season || "season1"; │
│ const seasonMatch = seasonParam.match(/^season(\d+)$/); │
│ const currentSeason = seasonMatch ? parseInt(seasonMatch[1], 10) : 1; │
│ │
│ // parse the slug for region/realm/dungeon using the actual URL segments │
│ const pathSegments = Astro.url.pathname.split("/").filter(Boolean); │
│ const seasonIdx = pathSegments.findIndex((segment) => │
│ /^season\d+$/i.test(segment), │
│ ); │
│ const slugParts = seasonIdx >= 0 ? pathSegments.slice(seasonIdx + 1) : []; │
│ │
│ // defaults │
│ let regionParam = "global"; │
│ let realmParam = ""; │
│ let dungeonParam = "temple-of-the-jade-serpent"; │
│ │
│ // Parse URL patterns: │
│ // /challenge-mode/season1/global/dungeon-slug │
│ // /challenge-mode/season1/region/all/dungeon-slug │
│ // /challenge-mode/season1/region/realm/dungeon-slug │
│ if (slugParts.length >= 2) { │
│ if (slugParts[0] === "global") { │
│ regionParam = "global"; │
│ realmParam = ""; │
│ dungeonParam = slugParts[1]; │
│ } else if (slugParts.length >= 3) { │
│ regionParam = slugParts[0]; │
│ realmParam = slugParts[1]; │
│ dungeonParam = slugParts[2]; │
│ } │
│ } │
│ │
│ // Check for page query param │
│ const pageParam = Astro.url.searchParams.get("page"); │
│ const currentPage = pageParam ? parseInt(pageParam, 10) : 1; │
│ │
│ // Get dungeon name and ID from slug │
│ let dungeonName = "Temple of the Jade Serpent"; │
│ const dungeonIdStr = dungeonSlugToId(dungeonParam); │
│ const dungeonId = dungeonIdStr ? parseInt(dungeonIdStr, 10) : 2; │
│ │
│ for (const [id, name] of Object.entries(DUNGEON_MAP)) { │
│ if (dungeonNameToSlug(name) === dungeonParam) { │
│ dungeonName = name; │
│ break; │
│ } │
│ } │
│ │
│ // Build scope label │
│ let scopeLabel: string; │
│ if (regionParam === "global") { │
│ scopeLabel = "Global"; │
│ } else if (realmParam && realmParam !== "all") { │
│ scopeLabel = `${regionParam.toUpperCase()} - ${realmParam}`; │
│ } else { │
│ scopeLabel = `${regionParam.toUpperCase()} - All Realms`; │
│ } │
│ │
│ // Fetch leaderboard data with graceful fallback when API file is missing │
│ const emptyLeaderboardData: LeaderboardData = { │
│ leading_groups: [], │
│ pagination: { │
│ currentPage: currentPage, │
│ pageSize: 25, │
│ totalPages: 1, │
│ hasNextPage: false, │
│ hasPrevPage: currentPage > 1, │
│ totalRuns: 0, │
│ }, │
│ }; │
│ │
│ let data: LeaderboardData = emptyLeaderboardData; │
│ │
│ try { │
│ data = await fetchLeaderboard( │
│ regionParam, │
│ realmParam || "all", │
│ dungeonId, │
│ currentPage, │
│ true, │
│ Astro.url.origin, │
│ currentSeason, │
│ ); │
│ } catch (error) { │
│ console.error("[Test Leaderboard] Error:", error); │
│ } │
│ --- │
│ │
│ <PageLayout │
│ title="Challenge Mode Dungeon Leaderboards" │
│ description="View the top Mist of Pandaria challenge mode records" │
│ > │
│ <main class="leaderboard-page"> │
│ <LeaderboardHeader │
│ season={currentSeason} │
│ dungeonName={dungeonName} │
│ dungeonSlug={dungeonParam} │
│ scopeLabel={scopeLabel} │
│ /> │
│ │
│ <PlayerSearch /> │
│ <LeaderboardTypeNav │
│ currentType="dungeon" │
│ currentRegion={regionParam} │
│ currentRealm={realmParam} │
│ currentSeason={currentSeason} │
│ currentDungeon={dungeonParam} │
│ /> │
│ │
│ <div class="cm-filters"> │
│ <LeaderboardScopeFilter │
│ currentRegion={regionParam} │
│ currentRealm={realmParam} │
│ currentSeason={currentSeason} │
│ leaderboardType="dungeon" │
│ currentDungeon={dungeonParam} │
│ /> │
│ <DungeonFilterSelect │
│ currentDungeon={dungeonParam} │
│ currentRegion={regionParam} │
│ currentRealm={realmParam} │
│ /> │
│ </div> │
│ │
│ <div id="leaderboard-content"> │
│ <LeaderboardTable │
│ type="dungeon" │
│ runs={data.leading_groups} │
│ currentPage={data.pagination.currentPage} │
│ pageSize={data.pagination.pageSize} │
│ region={regionParam} │
│ realm={realmParam} │
│ dungeon={dungeonId.toString()} │
│ /> │
│ </div> │
│ │
│ <Pagination │
│ currentPage={data.pagination.currentPage} │
│ totalPages={data.pagination.totalPages} │
│ hasNextPage={data.pagination.hasNextPage} │
│ hasPrevPage={data.pagination.hasPrevPage} │
│ totalRuns={data.pagination.totalRuns} │
│ baseUrl={Astro.url.pathname} │
│ /> │
│ </main> │
│ </PageLayout> │
│ │
│ <style> │
│ .leaderboard-page { │
│ max-width: 1200px; │
│ margin: 0 auto; │
│ padding: 20px; │
│ } │
│ │
│ @media (max-width: 768px) { │
│ .leaderboard-page { │
│ padding: 15px; │
│ } │
│ } │
│ </style> │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ ASTRO ──────────────────────────────┐
│ --- │
│ import PageLayout from "../../../layouts/Pag │
│ eLayout.astro"; │
│ import LeaderboardHeader from "../../../comp │
│ onents/Leaderboard/LeaderboardHeader/Leaderb │
│ oardHeader.astro"; │
│ import LeaderboardTable from "../../../compo │
│ nents/Leaderboard/LeaderboardTable/Leaderboa │
│ rdTable.astro"; │
│ import Pagination from "../../../components/ │
│ Leaderboard/Pagination/Pagination.astro"; │
│ import DungeonFilterSelect from "../../../co │
│ mponents/Leaderboard/DungeonFilterSelect/Dun │
│ geonFilterSelect.astro"; │
│ import LeaderboardScopeFilter from "../../.. │
│ /components/Leaderboard/LeaderboardScopeFilt │
│ er/LeaderboardScopeFilter.astro"; │
│ import LeaderboardTypeNav from "../../../com │
│ ponents/Leaderboard/LeaderboardTypeNav/Leade │
│ rboardTypeNav.astro"; │
│ import PlayerSearch from "../../../component │
│ s/PlayerSearch/PlayerSearch.astro"; │
│ import type { LeaderboardData } from "../../ │
│ ../lib/types"; │
│ import { │
│ DUNGEON_MAP, │
│ dungeonNameToSlug, │
│ dungeonSlugToId, │
│ } from "../../../lib/wow-constants"; │
│ import { fetchLeaderboard } from "../../../l │
│ ib/api"; │
│ │
│ export const prerender = false; │
│ │
│ // parse season from path parameter │
│ const seasonParam = Astro.params.season || " │
│ season1"; │
│ const seasonMatch = seasonParam.match(/^seas │
│ on(\d+)$/); │
│ const currentSeason = seasonMatch ? parseInt │
│ (seasonMatch[1], 10) : 1; │
│ │
│ // parse the slug for region/realm/dungeon u │
│ sing the actual URL segments │
│ const pathSegments = Astro.url.pathname.spli │
│ t("/").filter(Boolean); │
│ const seasonIdx = pathSegments.findIndex((se │
│ gment) => │
│ /^season\d+$/i.test(segment), │
│ ); │
│ const slugParts = seasonIdx >= 0 ? pathSegme │
│ nts.slice(seasonIdx + 1) : []; │
│ │
│ // defaults │
│ let regionParam = "global"; │
│ let realmParam = ""; │
│ let dungeonParam = "temple-of-the-jade-serpe │
│ nt"; │
│ │
│ // Parse URL patterns: │
│ // /challenge-mode/season1/global/dungeon-sl │
│ ug │
│ // /challenge-mode/season1/region/all/dungeo │
│ n-slug │
│ // /challenge-mode/season1/region/realm/dung │
│ eon-slug │
│ if (slugParts.length >= 2) { │
│ if (slugParts[0] === "global") { │
│ regionParam = "global"; │
│ realmParam = ""; │
│ dungeonParam = slugParts[1]; │
│ } else if (slugParts.length >= 3) { │
│ regionParam = slugParts[0]; │
│ realmParam = slugParts[1]; │
│ dungeonParam = slugParts[2]; │
│ } │
│ } │
│ │
│ // Check for page query param │
│ const pageParam = Astro.url.searchParams.get │
│ ("page"); │
│ const currentPage = pageParam ? parseInt(pag │
│ eParam, 10) : 1; │
│ │
│ // Get dungeon name and ID from slug │
│ let dungeonName = "Temple of the Jade Serpen │
│ t"; │
│ const dungeonIdStr = dungeonSlugToId(dungeon │
│ Param); │
│ const dungeonId = dungeonIdStr ? parseInt(du │
│ ngeonIdStr, 10) : 2; │
│ │
│ for (const [id, name] of Object.entries(DUNG │
│ EON_MAP)) { │
│ if (dungeonNameToSlug(name) === dungeonPar │
│ am) { │
│ dungeonName = name; │
│ break; │
│ } │
│ } │
│ │
│ // Build scope label │
│ let scopeLabel: string; │
│ if (regionParam === "global") { │
│ scopeLabel = "Global"; │
│ } else if (realmParam && realmParam !== "all │
│ ") { │
│ scopeLabel = `${regionParam.toUpperCase()} │
│ - ${realmParam}`; │
│ } else { │
│ scopeLabel = `${regionParam.toUpperCase()} │
│ - All Realms`; │
│ } │
│ │
│ // Fetch leaderboard data with graceful fall │
│ back when API file is missing │
│ const emptyLeaderboardData: LeaderboardData │
│ = { │
│ leading_groups: [], │
│ pagination: { │
│ currentPage: currentPage, │
│ pageSize: 25, │
│ totalPages: 1, │
│ hasNextPage: false, │
│ hasPrevPage: currentPage > 1, │
│ totalRuns: 0, │
│ }, │
│ }; │
│ │
│ let data: LeaderboardData = emptyLeaderboard │
│ Data; │
│ │
│ try { │
│ data = await fetchLeaderboard( │
│ regionParam, │
│ realmParam || "all", │
│ dungeonId, │
│ currentPage, │
│ true, │
│ Astro.url.origin, │
│ currentSeason, │
│ ); │
│ } catch (error) { │
│ console.error("[Test Leaderboard] Error:", │
│ error); │
│ } │
│ --- │
│ │
│ <PageLayout │
│ title="Challenge Mode Dungeon Leaderboards │
│ " │
│ description="View the top Mist of Pandaria │
│ challenge mode records" │
│ > │
│ <main class="leaderboard-page"> │
│ <LeaderboardHeader │
│ season={currentSeason} │
│ dungeonName={dungeonName} │
│ dungeonSlug={dungeonParam} │
│ scopeLabel={scopeLabel} │
│ /> │
│ │
│ <PlayerSearch /> │
│ <LeaderboardTypeNav │
│ currentType="dungeon" │
│ currentRegion={regionParam} │
│ currentRealm={realmParam} │
│ currentSeason={currentSeason} │
│ currentDungeon={dungeonParam} │
│ /> │
│ │
│ <div class="cm-filters"> │
│ <LeaderboardScopeFilter │
│ currentRegion={regionParam} │
│ currentRealm={realmParam} │
│ currentSeason={currentSeason} │
│ leaderboardType="dungeon" │
│ currentDungeon={dungeonParam} │
│ /> │
│ <DungeonFilterSelect │
│ currentDungeon={dungeonParam} │
│ currentRegion={regionParam} │
│ currentRealm={realmParam} │
│ /> │
│ </div> │
│ │
│ <div id="leaderboard-content"> │
│ <LeaderboardTable │
│ type="dungeon" │
│ runs={data.leading_groups} │
│ currentPage={data.pagination.current │
│ Page} │
│ pageSize={data.pagination.pageSize} │
│ region={regionParam} │
│ realm={realmParam} │
│ dungeon={dungeonId.toString()} │
│ /> │
│ </div> │
│ │
│ <Pagination │
│ currentPage={data.pagination.currentPa │
│ ge} │
│ totalPages={data.pagination.totalPages │
│ } │
│ hasNextPage={data.pagination.hasNextPa │
│ ge} │
│ hasPrevPage={data.pagination.hasPrevPa │
│ ge} │
│ totalRuns={data.pagination.totalRuns} │
│ baseUrl={Astro.url.pathname} │
│ /> │
│ </main> │
│ </PageLayout> │
│ │
│ <style> │
│ .leaderboard-page { │
│ max-width: 1200px; │
│ margin: 0 auto; │
│ padding: 20px; │
│ } │
│ │
│ @media (max-width: 768px) { │
│ .leaderboard-page { │
│ padding: 15px; │
│ } │
│ } │
│ </style> │
└──────────────────────────────────────────────┘
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET